package com.luhuiguo.cms.client.presenter;

import com.google.inject.Inject;
import com.luhuiguo.cms.shared.event.LoginEvent;
import com.luhuiguo.cms.shared.event.LoginEventHandler;
import com.luhuiguo.cms.shared.model.UserModel;
import com.luhuiguo.gwt.dispatcher.client.DispatcherAsync;
import com.luhuiguo.gwt.presenter.client.EventBus;
import com.luhuiguo.gwt.presenter.client.widget.WidgetDisplay;
import com.luhuiguo.gwt.presenter.client.widget.WidgetPresenter;

public class HeaderPresenter extends WidgetPresenter<HeaderPresenter.Display> {

    public interface Display extends WidgetDisplay {
        void showCurrentUser(UserModel user);
    }

    @SuppressWarnings("unused")
    private DispatcherAsync dispatcher;
    
    private UserModel user;

    @Inject
    public HeaderPresenter(Display display, EventBus eventBus, DispatcherAsync dispatcher) {
        super(display, eventBus);
        this.dispatcher = dispatcher;
    }

    @Override
    protected void onBind() {
        registerHandler(eventBus.addHandler(LoginEvent.TYPE, new LoginEventHandler() {

            public void onLogin(LoginEvent event) {
                user = event.getUser();
                display.showCurrentUser(user);
                
                //display.getUserText().setText(messages.welcome(event.getUser().getUsername()));
            }

        }));
    }

    @Override
    protected void onRevealDisplay() {

    }

    @Override
    protected void onUnbind() {

    }

}
